package club.justwill.single.assembler;

import club.justwill.single.bean.UserResp;
import club.justwill.single.persistence.jpo.User;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by luoyu on 1/3/16.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class UserAssemble {
    public List<UserResp> assembleUsers(List<User> userList){
        List<UserResp> userRespList = new ArrayList<UserResp>();
        for(User user: userList){
            UserResp userResp = assembleUser(user);
            userRespList.add(userResp);
        }
        return userRespList;
    }

    public UserResp assembleUser(User user){
        UserResp userResp = new UserResp();
        userResp.setUserId(user.getUserId()+"");
        userResp.setNickName(user.getNickName()+"");
        userResp.setSex(user.getSex()+"");
        userResp.setHead_icon(user.getHeadIcon()+"");
        userResp.setBirthday(user.getBirthday()+"");
        userResp.setBalance(user.getBalance()+"");
        userResp.setType(user.getType()+"");
        userResp.setCreationTime(user.getCreationTime()==null?"":user.getCreationTime().getTime()+"");
        userResp.setStatus(user.getStatus()+"");
        userResp.setAddress(user.getAddress()+"");
        userResp.setInvitationCode(user.getInvitationCode()+"");
        return userResp;
    }
}
